# File：01 mysql连接.py
# Author：信思智学
# Date ：2025/7/17 14:37
# Info：python+mysql ======>   pymysql
import pymysql

# 创建数据库连接  connection
conn = pymysql.connect(
    user="root",
    password="root",
    host="127.0.0.1",
    port=3306,
    database="spt2505"
)

# 通过数据库连接创建数据库对象
cur = conn.cursor()

username = input("请输入用户名")
password = input("请输入密码")
age = input("请输入年龄")
id = input("请输入要修改的id")
# 准备sql语句  添加

# 通过数据库对象执行sql  字典类型
# sql = "insert into t_user values (null,%s,%s,%s)"
# count = cur.execute(sql,(username,password,int(age)))
#
# sql = "delete from t_user where id = %s"
# count = cur.execute(sql,(int(id),))

sql = "update t_user set username = %s,password = %s,age = %s where id = %s"
count = cur.execute(sql,(username,password,int(age),int(id)))

print(count)

conn.commit()

# 关闭数据库对象
cur.close()
# 关闭数据库连接
conn.close()